/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using Amazon.ECS;
using Amazon.ECS.Model;

namespace Amazon.ECS.Samples
{

    /// <summary>
    /// Transaction Lookup  Samples
    /// </summary>
    public class TransactionLookupSample
    {
    
                                                                                     
        /// <summary>
        /// 
        /// <p/>
        /// The TransactionLookup operation returns information about up to ten purchases
        /// that have already taken place. Transaction IDs are created whenever a purchase
        /// request is made by a customer.
        /// <p/>
        /// For a specified transaction ID, TransactionLookup returns:
        /// <ul>
        /// <li>Price details</li>
        /// <li>Sale date</li>
        /// <li>Shipping details</li>
        /// <li>Seller details</li>
        /// <li>Item's condition </li>
        /// </ul>
        /// <p/>
        /// For privacy reasons, this operation does not return information about the customer
        /// who purchased the items.
        /// <p/>
        /// <b>Available Response Groups</b>:
        /// <ul>
        /// <li>Request</li>
        /// <li>TransactionDetails</li>
        /// </ul>
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonECS service</param>
        /// <param name="request">TransactionLookup request</param>
        public static void InvokeTransactionLookup(AmazonECS service, params TransactionLookupRequest [] request) 
        {
            try 
            {
                TransactionLookupResponse response = service.TransactionLookup(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        TransactionLookupResponse");
                if (response.IsSetOperationRequest()) 
                {
                    Console.WriteLine("            OperationRequest");
                    OperationRequest  operationRequest = response.OperationRequest;
                    if (operationRequest.IsSetHTTPHeaders()) 
                    {
                        Console.WriteLine("                HTTPHeaders");
                        HTTPHeaders  HTTPHeaders = operationRequest.HTTPHeaders;
                    } 
                    if (operationRequest.IsSetRequestId()) 
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", operationRequest.RequestId);
                    }
                    if (operationRequest.IsSetArguments()) 
                    {
                        Console.WriteLine("                Arguments");
                        Arguments  arguments = operationRequest.Arguments;
                    } 
                    if (operationRequest.IsSetRequestProcessingTime()) 
                    {
                        Console.WriteLine("                RequestProcessingTime");
                        Console.WriteLine("                    {0}", operationRequest.RequestProcessingTime);
                    }
                } 
                List<Transactions> transactionsList = response.Transactions;
                foreach (Transactions transactions in transactionsList) 
                {
                    Console.WriteLine("            Transactions");
                    if (transactions.IsSetTotalResults()) 
                    {
                        Console.WriteLine("                TotalResults");
                        Console.WriteLine("                    {0}", transactions.TotalResults);
                    }
                    if (transactions.IsSetTotalPages()) 
                    {
                        Console.WriteLine("                TotalPages");
                        Console.WriteLine("                    {0}", transactions.TotalPages);
                    }
                    List<Transaction> transactionList = transactions.Transaction;
                    foreach (Transaction transaction in transactionList) 
                    {
                        Console.WriteLine("                Transaction");
                        if (transaction.IsSetTransactionId()) 
                        {
                            Console.WriteLine("                    TransactionId");
                            Console.WriteLine("                        {0}", transaction.TransactionId);
                        }
                        if (transaction.IsSetSellerId()) 
                        {
                            Console.WriteLine("                    SellerId");
                            Console.WriteLine("                        {0}", transaction.SellerId);
                        }
                        if (transaction.IsSetCondition()) 
                        {
                            Console.WriteLine("                    Condition");
                            Console.WriteLine("                        {0}", transaction.Condition);
                        }
                        if (transaction.IsSetTransactionDate()) 
                        {
                            Console.WriteLine("                    TransactionDate");
                            Console.WriteLine("                        {0}", transaction.TransactionDate);
                        }
                        if (transaction.IsSetTransactionDateEpoch()) 
                        {
                            Console.WriteLine("                    TransactionDateEpoch");
                            Console.WriteLine("                        {0}", transaction.TransactionDateEpoch);
                        }
                        if (transaction.IsSetSellerName()) 
                        {
                            Console.WriteLine("                    SellerName");
                            Console.WriteLine("                        {0}", transaction.SellerName);
                        }
                        if (transaction.IsSetPayingCustomerId()) 
                        {
                            Console.WriteLine("                    PayingCustomerId");
                            Console.WriteLine("                        {0}", transaction.PayingCustomerId);
                        }
                        if (transaction.IsSetOrderingCustomerId()) 
                        {
                            Console.WriteLine("                    OrderingCustomerId");
                            Console.WriteLine("                        {0}", transaction.OrderingCustomerId);
                        }
                        if (transaction.IsSetTotals()) 
                        {
                            Console.WriteLine("                    Totals");
                            TransactionTotals  totals = transaction.Totals;
                            if (totals.IsSetTotal()) 
                            {
                                Console.WriteLine("                        Total");
                                Price  total = totals.Total;
                                if (total.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", total.Amount);
                                }
                                if (total.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", total.CurrencyCode);
                                }
                                if (total.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", total.FormattedPrice);
                                }
                            } 
                            if (totals.IsSetSubtotal()) 
                            {
                                Console.WriteLine("                        Subtotal");
                                Price  subtotal = totals.Subtotal;
                                if (subtotal.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", subtotal.Amount);
                                }
                                if (subtotal.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", subtotal.CurrencyCode);
                                }
                                if (subtotal.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", subtotal.FormattedPrice);
                                }
                            } 
                            if (totals.IsSetTax()) 
                            {
                                Console.WriteLine("                        Tax");
                                Price  tax = totals.Tax;
                                if (tax.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", tax.Amount);
                                }
                                if (tax.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", tax.CurrencyCode);
                                }
                                if (tax.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", tax.FormattedPrice);
                                }
                            } 
                            if (totals.IsSetShippingCharge()) 
                            {
                                Console.WriteLine("                        ShippingCharge");
                                Price  shippingCharge = totals.ShippingCharge;
                                if (shippingCharge.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", shippingCharge.Amount);
                                }
                                if (shippingCharge.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", shippingCharge.CurrencyCode);
                                }
                                if (shippingCharge.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", shippingCharge.FormattedPrice);
                                }
                            } 
                            if (totals.IsSetPromotion()) 
                            {
                                Console.WriteLine("                        Promotion");
                                Price  promotion = totals.Promotion;
                                if (promotion.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", promotion.Amount);
                                }
                                if (promotion.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", promotion.CurrencyCode);
                                }
                                if (promotion.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", promotion.FormattedPrice);
                                }
                            } 
                        } 
                        if (transaction.IsSetTransactionItems()) 
                        {
                            Console.WriteLine("                    TransactionItems");
                            TransactionItems  transactionItems = transaction.TransactionItems;
                            List<TransactionItem> transactionItemList = transactionItems.TransactionItem;
                            foreach (TransactionItem transactionItem in transactionItemList) 
                            {
                                Console.WriteLine("                        TransactionItem");
                                if (transactionItem.IsSetTransactionItemId()) 
                                {
                                    Console.WriteLine("                            TransactionItemId");
                                    Console.WriteLine("                                {0}", transactionItem.TransactionItemId);
                                }
                                if (transactionItem.IsSetQuantity()) 
                                {
                                    Console.WriteLine("                            Quantity");
                                    Console.WriteLine("                                {0}", transactionItem.Quantity);
                                }
                                if (transactionItem.IsSetUnitPrice()) 
                                {
                                    Console.WriteLine("                            UnitPrice");
                                    Price  unitPrice = transactionItem.UnitPrice;
                                    if (unitPrice.IsSetAmount()) 
                                    {
                                        Console.WriteLine("                                Amount");
                                        Console.WriteLine("                                    {0}", unitPrice.Amount);
                                    }
                                    if (unitPrice.IsSetCurrencyCode()) 
                                    {
                                        Console.WriteLine("                                CurrencyCode");
                                        Console.WriteLine("                                    {0}", unitPrice.CurrencyCode);
                                    }
                                    if (unitPrice.IsSetFormattedPrice()) 
                                    {
                                        Console.WriteLine("                                FormattedPrice");
                                        Console.WriteLine("                                    {0}", unitPrice.FormattedPrice);
                                    }
                                } 
                                if (transactionItem.IsSetTotalPrice()) 
                                {
                                    Console.WriteLine("                            TotalPrice");
                                    Price  totalPrice = transactionItem.TotalPrice;
                                    if (totalPrice.IsSetAmount()) 
                                    {
                                        Console.WriteLine("                                Amount");
                                        Console.WriteLine("                                    {0}", totalPrice.Amount);
                                    }
                                    if (totalPrice.IsSetCurrencyCode()) 
                                    {
                                        Console.WriteLine("                                CurrencyCode");
                                        Console.WriteLine("                                    {0}", totalPrice.CurrencyCode);
                                    }
                                    if (totalPrice.IsSetFormattedPrice()) 
                                    {
                                        Console.WriteLine("                                FormattedPrice");
                                        Console.WriteLine("                                    {0}", totalPrice.FormattedPrice);
                                    }
                                } 
                                if (transactionItem.IsSetASIN()) 
                                {
                                    Console.WriteLine("                            ASIN");
                                    Console.WriteLine("                                {0}", transactionItem.ASIN);
                                }
                                if (transactionItem.IsSetChildTransactionItems()) 
                                {
                                    Console.WriteLine("                            ChildTransactionItems");
                                    ChildTransactionItems  childTransactionItems = transactionItem.ChildTransactionItems;
                                } 
                            }
                        } 
                        if (transaction.IsSetShipments()) 
                        {
                            Console.WriteLine("                    Shipments");
                            TransactionShipments  shipments = transaction.Shipments;
                            List<Shipment> shipmentList = shipments.Shipment;
                            foreach (Shipment shipment in shipmentList) 
                            {
                                Console.WriteLine("                        Shipment");
                                if (shipment.IsSetCondition()) 
                                {
                                    Console.WriteLine("                            Condition");
                                    Console.WriteLine("                                {0}", shipment.Condition);
                                }
                                if (shipment.IsSetDeliveryMethod()) 
                                {
                                    Console.WriteLine("                            DeliveryMethod");
                                    Console.WriteLine("                                {0}", shipment.DeliveryMethod);
                                }
                                if (shipment.IsSetShipmentItems()) 
                                {
                                    Console.WriteLine("                            ShipmentItems");
                                    ShipmentItems  shipmentItems = shipment.ShipmentItems;
                                    List<String> transactionItemIdList  =  shipmentItems.TransactionItemId;
                                    foreach (String transactionItemId in transactionItemIdList) 
                                    { 
                                        Console.WriteLine("                                TransactionItemId");
                                        Console.WriteLine("                                    {0}", transactionItemId);
                                    }	
                                } 
                                if (shipment.IsSetPackages()) 
                                {
                                    Console.WriteLine("                            Packages");
                                    ShipmentPackages  packages = shipment.Packages;
                                    List<ShipmentPackage> packageList = packages.Package;
                                    foreach (ShipmentPackage package in packageList) 
                                    {
                                        Console.WriteLine("                                Package");
                                        if (package.IsSetTrackingNumber()) 
                                        {
                                            Console.WriteLine("                                    TrackingNumber");
                                            Console.WriteLine("                                        {0}", package.TrackingNumber);
                                        }
                                        if (package.IsSetCarrierName()) 
                                        {
                                            Console.WriteLine("                                    CarrierName");
                                            Console.WriteLine("                                        {0}", package.CarrierName);
                                        }
                                    }
                                } 
                            }
                        } 
                    }
                }

            } 
            catch (AmazonECSException ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }
                    }
}
